package com.superquan.selfstudybootmybatis.entity.common;


import lombok.Data;

import java.io.Serializable;
/**
 * @author zwq
 * @description 返回实体
 * @date 2022/3/29
 */
//@Data
public class ResultBean<T> implements Serializable {

    /**
     * 状态码
     */
    private int code;
    /**
     * 状态信息
     */
    private String message;
    /**
     * 返回结果
     */
    private T data;

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public static<T> ResultBean FAIL(int code, String msg){
        ResultBean<T> bean = new ResultBean<>();
        bean.setCode(code);
        bean.setMessage(msg);
        return bean;
    }

    public static<T> ResultBean FAIL(String msg){
        return FAIL(1, msg);
    }

    public static<T> ResultBean FAIL(){
        return FAIL(1, "");
    }

    public static<T> ResultBean SUCCESS(T t){
        ResultBean<T> bean = new ResultBean<>();
        bean.setCode(0);
        bean.setMessage("成功");
        bean.setData(t);
        return bean;
    }

    public static<T> ResultBean SUCCESS(){
        return SUCCESS(null);
    }

}
